package com.example.neusoftfood_426wxy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.neusoftfood_426wxy.R;
import com.example.neusoftfood_426wxy.beans.UserInfo;
import com.example.neusoftfood_426wxy.listener.RetrofitListener;
import com.example.neusoftfood_426wxy.model.UserModel;

public class LoginActivity extends AppCompatActivity implements RetrofitListener<UserInfo> {
    private EditText etuser,etpass;
    private Button btnlogin;
   //private Button button;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       Button button=(Button)findViewById(R.id.button);

        initViews();

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(LoginActivity.this,Register.class);

                startActivity(intent);
            }
        });
    }
    private void initViews(){
        etuser=findViewById(R.id.etuser);
        etpass=findViewById(R.id.etpass);
        btnlogin=findViewById(R.id.btnlogin);
       //button=findViewById(R.id.button);



        btnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserModel userModel = new UserModel();
                userModel.userLogin(etuser.getText().toString().trim(), etpass.getText().toString().trim(),LoginActivity.this);

               // Intent intent=new Intent(LoginActivity.this,Register.class);

                //startActivity(intent);


            }

        });

    }



    @Override
    public void onSuccess(UserInfo userInfo, int flag) {
           if(!userInfo.getUserid().equals("0"))
               Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
           else
               Toast.makeText(LoginActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFail() {
        Toast.makeText(LoginActivity.this,"网络错误",Toast.LENGTH_SHORT).show();
    }
}
